<?php
class IndexController extends IG_Controller_Action
{
    public function indexAction ()
    {
        $menu = new System_Model_Menu();
        if ($this->_getParam('load') == 'menu') {
            $id = (int) $this->_getParam('id');
            if ($id == -1) {
                $userMenu = new System_Model_UserMenu();
                $data = $userMenu->fetchAll(array(
                    'employee_id=?' => $this->getIdentity()->getEmployeeId()
                ))->toArray();
                array_push($data, array(
                            'id'        => 0,
                            'parent_id' => -1,
                            'type'      => null,
                            'url'       => null,
                            'title'     => null,
                 ));
                 $id = 0;
            } else {
                $data = $menu->getByParentId($id);
            }
            $this->_helper->json($this->_helper->jstree($data, $id));
        }
        $this->disableLayout();

        $this->view->modules = $menu->getByParentId(0);
        //$this->view->modules = $menu->fetchAll(null, array('position'));
    }
}